package views;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import core.ScheduledActivity;
import dat065.app.R;

public class TimeChoser extends Activity {
	private TextView mTimeDisplay;
	private Button mPickTime;
	private TextView dateDisplay;
	private Button timeDone;
	//Should get with activity start
	private int day = 122;
	private int month = 22;
	private int year = 2001;

	private int mHour;
	private int mMinute;

	//List from main with all the activities
	private ArrayList<ScheduledActivity> list =  new ArrayList<ScheduledActivity>();

	static final int TIME_DIALOG_ID = 0;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.timechoser);

		// capture our View elements
		mTimeDisplay = (TextView) findViewById(R.id.timeDisplay);
		mPickTime = (Button) findViewById(R.id.pickTime);
		dateDisplay = (TextView) findViewById(R.id.timechoserDate);
		timeDone = (Button) findViewById(R.id.timeDone);

		// add a click listener to the mPickTime button
		mPickTime.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				showDialog(TIME_DIALOG_ID);
			}
		});
		timeDone.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				/*  //Should add activity to the list in main and send the user back to Front view 
            	list = Main.getList();
            	list.add(new ScheduledActivity(day,month,year,mHour,mMinute));
            	setResult(--- TO FRONT ---);
				finish();

				 */
			}
		});

		dateDisplay.setText(year + " - " + month +" - " + day);

	}

	private void updateDisplay() {
		mTimeDisplay.setText(
				new StringBuilder()
				.append(pad(mHour)).append(":")
				.append(pad(mMinute)));
	}

	private static String pad(int c) {
		if (c >= 10)
			return String.valueOf(c);
		else
			return "0" + String.valueOf(c);
	}
	private TimePickerDialog.OnTimeSetListener mTimeSetListener =
		new TimePickerDialog.OnTimeSetListener() {


		public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
			mHour = hourOfDay;
			mMinute = minute;



			updateDisplay();
		}
	};

	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case TIME_DIALOG_ID:
			return new TimePickerDialog(this,
					mTimeSetListener, mHour, mMinute, false);
		}
		return null;
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}


}
